/* eslint-disable no-unused-vars */
import React, { useEffect, useImperativeHandle, useState, forwardRef } from 'react';
import { Layout, message, Modal, Popconfirm, Table, Space, Tag, Button } from 'antd';
// import styles from './style.less';
// import ControlPlus from './controls/ControlPlus';

const DesignHistroy = forwardRef((props, ref) => {
  const { formkey } = props;
  const [edit, setEdit] = useState(false);

  useImperativeHandle(ref, () => ({
    setEdit,
  }));

  useEffect(() => {}, []);

  const columns = [
    {
      title: 'Name',
      dataIndex: 'name',
      key: 'name',
      render: (text) => <a>{text}</a>,
    },
    {
      title: 'Age',
      dataIndex: 'age',
      key: 'age',
    },
    {
      title: 'Address',
      dataIndex: 'address',
      key: 'address',
    },
    {
      title: 'Tags',
      key: 'tags',
      dataIndex: 'tags',
      render: (tags) => (
        <>
          {tags.map((tag) => {
            let color = tag.length > 5 ? 'geekblue' : 'green';
            if (tag === 'loser') {
              color = 'volcano';
            }
            return (
              <Tag color={color} key={tag}>
                {tag.toUpperCase()}
              </Tag>
            );
          })}
        </>
      ),
    },
    {
      title: 'Action',
      key: 'action',
      render: (text, record) => (
        <Space size="middle">
          <a>Invite {record.name}</a>
          <a>Delete</a>
        </Space>
      ),
    },
  ];

  const data = [
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      address: 'New York No. 1 Lake Park',
      tags: ['nice', 'developer'],
    },
    {
      key: '2',
      name: 'Jim Green',
      age: 42,
      address: 'London No. 1 Lake Park',
      tags: ['loser'],
    },
    {
      key: '3',
      name: 'Joe Black',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      tags: ['cool', 'teacher'],
    },
  ];

  const clearVersion = function () {
    message.info('已清空所有版本');
  };

  const saveSystemVersion = function () {
    message.info('已恢复系统默认版本');
  };

  return (
    <Modal
      visible={edit}
      title="重置表单历史版本"
      onOk={() => {
        setEdit(false);
      }}
    >
      <Popconfirm
        placement="top"
        title="操作确认"
        onConfirm={() => {
          clearVersion();
        }}
      >
        <Button type="link">清空所有版本</Button>
      </Popconfirm>
      <Popconfirm
        placement="top"
        title="操作确认"
        onConfirm={() => {
          saveSystemVersion();
        }}
      >
        <Button type="link">恢复系统默认版本</Button>
      </Popconfirm>
      <Table columns={columns} dataSource={data} />
    </Modal>
  );
});

export default DesignHistroy;
